/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.migo.utils;


import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * @author paik
 */
public class PhoneUtil {
    public static boolean isMobileNO(String mobiles) {
        Pattern p = Pattern.compile("^[1][3-8]\\d{9}$|^([6|9])\\d{7}$|^[0][9]\\d{8}$|^[6]([8|6])\\d{5}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }

    public static void sendPhoneCode(String code, String phone, String ip) {
        aliyunSendSms(phone, code, ip);
    }

    /**
     * 国内发送短信验证
     *
     * @param phone
     * @param code
     * @param ip
     */
    public static void aliyunSendSms(String phone, String code, String ip) {
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("code", code));
        formparams.add(new BasicNameValuePair("phone", phone));
        formparams.add(new BasicNameValuePair("ip", ip));
        formparams.add(new BasicNameValuePair("templateCode", "SMS_190783783"));
        new HttpClientUtils().request(formparams, SMS.SMSURL + "/api/sms/sendChinaAliyunSms");
    }

    /**
     * 国际发送短信验证码
     *
     * @param code
     * @param phone
     * @param ip
     */
    public static void sendInternationalPhoneCode(String code, String phone, String ip) {
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("code", code));
        formparams.add(new BasicNameValuePair("phone", phone));
        formparams.add(new BasicNameValuePair("ip", ip));
        formparams.add(new BasicNameValuePair("templateCode", "SMS_176936375"));
        String result = new HttpClientUtils().request(formparams, SMS.SMSURL + "/api/sms/sendChinaAliyunSms");
    }



    public static void main(String[] args) {
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("code", "123456"));
        formparams.add(new BasicNameValuePair("phone", "818035969731"));
        formparams.add(new BasicNameValuePair("ip", "1.2.1.1"));
        formparams.add(new BasicNameValuePair("templateCode", "SMS_176936375"));
        String result = new HttpClientUtils().request(formparams, "http://api.sms.powervision.me/api/sms/sendChinaAliyunSms");
    }
}
